import os
from urllib.parse import quote_plus

from pydantic_settings import BaseSettings

username = quote_plus(os.getenv('DB_USERNAME', 'postgres'))
password = quote_plus(os.getenv('DB_PASSWORD', 'postgres'))
dbname = os.getenv('DB_DATABASE')
db_host = os.getenv('DB_HOST')
db_port = os.getenv('DB_PORT')


class Settings(BaseSettings):
    DB_USERNAME: str = "postgres"
    DB_PASSWORD: str = "postgres"
    DB_DATABASE: str = "postgres"
    DB_HOST: str = "localhost"
    DB_PORT: int = 5432

    # DATABASE_URL: str = f"postgresql+asyncpg://{username}:{password}@{db_host}:{db_port}/{dbname}"
    SECRET_KEY: str = "super-secret"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30 * 24 * 60 * 60
    ALLOW_ORIGINS: str = "*"
    # REDIS_URL: str = "redis://localhost:6379/0"

    REDIS_HOST: str = "localhost"
    REDIS_PORT: int = 6379
    REDIS_DB: int = 0
    REDIS_USERNAME: str = "postgres"
    REDIS_PASSWORD: str = "postgres"
    # CELERY_REDIS_URL: str = "redis://localhost:6379/0"
    @property
    def DATABASE_URL(self) -> str:
        return (
            f"postgresql+asyncpg://{self.DB_USERNAME}:{self.DB_PASSWORD}"
            f"@{self.DB_HOST}:{self.DB_PORT}/{self.DB_DATABASE}"
        )

    @property
    def CELERY_BROKER_URL(self) -> str:
        return (
            f"redis://{self.REDIS_USERNAME}:{self.REDIS_PASSWORD}"
            f"@{self.REDIS_HOST}:{self.REDIS_PORT}/{self.REDIS_DB}"
        )


settings = Settings()
